package com.changgou.search.listener;

import com.changgou.search.service.EsManagerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 商品上架的消费者监听器
 */
@Component
public class GoodsUpListener {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private EsManagerService esManagerService;

    @RabbitListener(queues = "search_add_queue")
    public void msgHandle(String spuId){
        logger.info("商品上架MQ监听器，获取商品spuId：{}", spuId);
        //调用根据spuId查询商品数据后并导入数据到ES的接口
        esManagerService.importBySpuId(spuId);

        logger.info("根据商品spuId：{}导入数据到ES完毕!", spuId);
    }
}
